package com.zzp.zjs_bos.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zzp.zjs_bos.dao.IStaffDao;
import com.zzp.zjs_bos.domain.Staff;
import com.zzp.zjs_bos.service.IStaffService;
import com.zzp.zjs_bos.utils.PageBean;

@Service
@Transactional
public class StaffServiceImpl implements IStaffService {
	
	@Resource
	 protected IStaffDao staffDao;

	public void save(Staff model) {
		staffDao.save(model);
	}

	public void pageQuery(PageBean pageBean,Staff model) {
		DetachedCriteria dc = pageBean.getDetachedCriteria().forClass(model.getClass());
		
		if(StringUtils.isNotBlank(model.getId())){
			dc.add(Restrictions.eq("id", model.getId()));
		}
		
		if( StringUtils.isNotBlank(model.getName())){
			dc.add(Restrictions.like("name", "%"+model.getName()+"%"));
		}
		
		if( StringUtils.isNotBlank(model.getTelephone()) ){
			dc.add(Restrictions.like("telephone", "%"+model.getTelephone()+"%"));
		}
		
		if(StringUtils.isNotBlank(model.getStation())){
			dc.add(Restrictions.like("station", model.getStation()));
		}
		if(model.getHaspda() == "1"){
			dc.add(Restrictions.eq("haspda", "1"));
		}
		
		if(StringUtils.isNotBlank(model.getStandard())){
			dc.add(Restrictions.like("standard", model.getStandard()));
		}
		
		pageBean.setDetachedCriteria(dc);

		staffDao.pageQuery(pageBean);
	}

	
	public void delete(String ids) {
		String[] sid = ids.split(",");
		for (int i = 0; i < sid.length; i++) {
			String id = sid[i];
			Staff staff = staffDao.findById(id);
			staff.setDeltag("1");
		}
	}

	public Staff findById(String id) {
		return staffDao.findById(id);
	}

	public void update(Staff staff) {
		staffDao.update(staff);
	}

	public void recover(String ids) {
		String[] sid = ids.split(",");
		for (int i = 0; i < sid.length; i++) {
			String id = sid[i];
			Staff staff = staffDao.findById(id);
			staff.setDeltag("0");
		}
		
	}

	public List<Staff> findSome(DetachedCriteria dc) {
		return staffDao.findByCriteria(dc);
	}

			



	
	
	

}
